﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Diagnostics;

namespace MSDNWebcast.Converter
{
    /// <summary>
    /// 当透明度为0时不可见
    /// </summary>
    [ValueConversion(typeof(double), typeof(Visibility))]
    public class OpacityToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Debug.Assert(value is double, "value should be a doublVisibilitye");
            Debug.Assert(targetType.IsAssignableFrom(typeof(Visibility)), "value should be a Visibility");
            return (double)value <= 0 ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
